package com.zrrd.yunchmall.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zrrd.yunchmall.product.entity.Product;
import com.zrrd.yunchmall.product.entity.SkuStock;
import com.zrrd.yunchmall.product.service.IProductService;
import com.zrrd.yunchmall.product.service.ISkuStockService;
import com.zrrd.yunchmall.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 * sku的库存 前端控制器
 * </p>
 *
 * @author YeKong
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/sku")
@Api(tags = "商品服务-库存模块")
public class SkuStockController {
    @Autowired
    private ISkuStockService skuStockService;

    @ApiOperation("获取库存信息")
    @GetMapping("/{pid}")
    public ResponseResult sku(@PathVariable("pid") int pid) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("product_id",pid);
        List<SkuStock> skuStockList = skuStockService.list(queryWrapper);
        return new ResponseResult(200, "查询成功", skuStockList);
    }
    @ApiOperation("修改")
    @PostMapping("/update/{pid}")
    public ResponseResult update(@PathVariable("pid") long pid,
                                 @RequestBody SkuStock skuStock) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("id", pid);
        skuStockService.update(skuStock, updateWrapper);
        return new ResponseResult(200, "修改成功");
    }
}
